home *** CD-ROM | disk | FTP | other *** search
/ Game Programming in C++ - Start to Finish / GameProgrammingS.iso / Peon / PeonSDK-Win32-1.0.0.exe / {app} / PeonMain / source / IApplication.cpp < prev    next >
C/C++ Source or Header  |  2005-11-20  |  1KB  |  64 lines

  1.  
  2. #include "FileLogger.h"
  3. #include "IApplication.h"
  4.  
  5. namespace peon
  6. {
  7.  
  8.     IApplication::IApplication()
  9.     {
  10.         m_pCurrentState = NULL;
  11.     }
  12.  
  13.     IApplication::~IApplication()
  14.     {
  15.     }
  16.  
  17.     bool IApplication::loadState(int key, IApplicationState* pState)
  18.     {
  19.  
  20.         if(!pState->onLoad())
  21.         {
  22.             return false;
  23.         }
  24.  
  25.         m_oStates.insert(std::make_pair(key, pState));
  26.  
  27.         return true;
  28.     }
  29.  
  30.     void IApplication::setCurrentState( int key )
  31.     {
  32.  
  33.         std::map<int, IApplicationState*>::iterator it;
  34.         it = m_oStates.find(key);
  35.         if (it == m_oStates.end())
  36.         {
  37.             FileLogger::getSingleton().logError("IApplication", "Couldn't find state");
  38.             return;
  39.         }
  40.         else
  41.         {
  42.             m_pCurrentState = it->second;
  43.  
  44.         }
  45.     }
  46.  
  47.     void IApplication::unloadStates()
  48.     {
  49.         IApplicationState* pState;
  50.         for(std::map<int, IApplicationState*>::iterator it = m_oStates.begin();
  51.             it != m_oStates.end();
  52.             it++)
  53.         {
  54.             pState = (IApplicationState*)it->second;
  55.             pState->onUnload();
  56.             PEON_DELETE( pState );
  57.  
  58.         }
  59.  
  60.         //clear the map
  61.         m_oStates.clear();
  62.  
  63.     }
  64. }